<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改</title>
</head>
<body>
<h1>修改员工页面</h1>
<form action=""> <!--v-model双向绑定 readonly标记只读-->
    <input type="text" name="id" v-model="emp.id" readonly placeholder="id">
    <input type="text" name="name" v-model="emp.name" placeholder="名字">
    <input type="text" name="job" v-model="emp.job" placeholder="工作">
    <input type="text" name="sal" v-model="emp.sal" placeholder="工资">
    <input type="button" value="修改" @click="update()">
</form>
<!--引入vue和axios-->
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script>
    let v = new Vue({
        el:"form",
        data:{
            emp:{}
        },
        created:function (){
            //页面刷新完毕立即执行的代码写在整理
            //得到地址栏的id
            let id = location.search.split("=")[1];
            console.log("id="+id);
            axios.get("selectById?id="+id).then(function (response){
               v.emp=response.data;
            });
        },
        methods:{
            update:function (){
                //得到form表单中的数据
                let data = new FormData(document.querySelector("form"))
                axios.post("/update",data).then(function (){
                    alert("修改完成!")
                    location.href="/select.html"; //回到列表页面
                })
            }
        }

    })
</script>
</body>
</html>